# -*- coding: utf-8 -*-
"""
Created on Fri Aug 26 11:04:27 2022

@author: xiong
"""
import re
import hashlib
import time

def sqlLikesTemplate(data,taskid):
    if re.findall(r"id=(\d*)",data["user_url"]):
        userid = re.findall(r"id=(\d*)",data["user_url"])[0]
        md5_userid = hashlib.md5(userid.encode(encoding='UTF-8')).hexdigest()
    else:
        userid = ""
        md5_userid = ""
    sql = """INSERT INTO gather_facebook_post_like
            (vc_id,vc_target_user_id,vc_relation_user_id,vc_post_id,vc_user_url,vc_user_id,vc_photo_url,vc_photo_url_local,vc_nickname,text_content,dt_gather_time,vc_task_type,vc_md5) 
             VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')"""%(
            hashlib.md5(str(time.time()).encode(encoding='UTF-8')).hexdigest(),#vc_id
            md5_userid ,#vc_target_user_id
            '',#vc_relation_user_id
            data["post_id"],#vc_post_id
            data["user_url"],#vc_user_url
            userid,#vc_user_id
            data['user_profile_img'],#vc_photo_url
            data['url_local'],#vc_photo_url_local
            data["user_name"],#vc_nickname
            '',#text_content
            time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(data["dt_gather_time"])),#dt_gather_time
            '',#vc_task_type
            hashlib.md5((taskid+data["post_id"]).encode(encoding='UTF-8')).hexdigest(),#vc_md5
    )
    return sql